package com.coollang.smartbra.utils;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;

public class TranslucentSystemBarUtils {


    /**
     * 沉浸式状态栏
     *
     * @return
     */
    @SuppressLint("NewApi")
    @TargetApi(Build.VERSION_CODES.KITKAT)
    public static Boolean translucentSystemBar(Activity context, int id) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            context.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            context.getWindow().setStatusBarColor(context.getResources().getColor(id));
        }
        return false;
    }

    /**
     * 单个activity
     */
    public static void showChenJinZhuangTaiLan(View statusbar, Activity context, View content) {
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = context.getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            context.getWindow().setStatusBarColor(Color.TRANSPARENT);
            statusbar.setVisibility(View.VISIBLE);
        } else {
            statusbar.setVisibility(View.GONE);
            content.setFitsSystemWindows(true);
        }
    }

    /**
     * 带fragment的activity
     *
     * @param context
     * @param content
     */
    public static void showChenJinZhuangTaiLan(Activity context, View content) {
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = context.getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
//			View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION|
//			context.getWindow().setNavigationBarColor(Color.TRANSPARENT);
            context.getWindow().setStatusBarColor(Color.TRANSPARENT);
        } else {
            content.setFitsSystemWindows(true);
        }
    }

    /**
     * fragment在Activity中
     *
     * @param statusbar 沉浸式状态栏
     */
    public static void showChenJinZhuangTaiLan(View statusbar) {
        if (Build.VERSION.SDK_INT >= 21) {
            statusbar.setVisibility(View.VISIBLE);
        } else {
            statusbar.setVisibility(View.GONE);
        }
    }
}
